package DS0419;

public class NodeQueue {
    private Node rear;
    private Node front ;
    private int leng;
    private Node head =null;

    //初始化
    public void initQueue(){
        head=new Node();
        rear = new Node();
        front = new Node();
        front=head;
        rear = head;
    }


    //插入
    public void enQueue(Student date){
            Node e=new Node();
            e.date=date;
            if(rear==head)
            {
                rear=e;
                head.next=e;
                front.next=e;
            }else
            {
                rear.next=e;
                rear=e;
            }
        }

    //清除
    public void delQueue(){
        front =front.next;
        /*Student stu = null;
       if(rear==head){
           System.out.println("此队列为空");
       }else{
           stu=front.next.date;
           if(front.next==rear){
               front.next =rear;
               rear = head;
           }
           else{
               front.next = front.next.next;
           }

       }
        return stu ;*/
    }
    //清零
    public void clear(){

        rear=null;
        front=null;
        leng=0;
    }
    //长度
    public int length(){
        return leng;
    }
    //打印
    public void display(){
        if(head.next==null){
            System.out.println("此链式对列为空");
            return;
        }
        for(Node node=front;node!=rear;node=node.next){
            System.out.print(node.date+"  ");
        }
        System.out.println();
    }

    public boolean empty(){
        return leng==0;
    }

    public Student element(){
        return front.date;
    }
}
